//
//  XNLoginRequest.m
//  XINNingOA
//
//  Created by samuel on 2021/7/12.
//

#import "XNLoginRequest.h"
#import <JPUSHService.h>

@implementation XNLoginRequest
{
    NSString *_password;
    NSString *_username;
}

- (instancetype)initWithUsername:(NSString *)username Password:(NSString *)password
{
    self = [super init];
    if (self) {
        _password = password;
        _username = username;
    }
    return self;
}

- (NSString *)requestUrl
{
    return @"/api/User/Login";
}

- (YTKRequestMethod)requestMethod
{
    return YTKRequestMethodPOST;
}

- (id)requestArgument
{
    NSLog(@"----%@",[JPUSHService registrationID]);
    return @{
        @"password":_password,
        @"account":_username,
        @"RegistrationID": [JPUSHService registrationID] ? [JPUSHService registrationID] : @"",
        @"DeviceType":@"1",
    };
}


- (BOOL)success
{
    NSDictionary *response = [self responseJSONObject];
    if ([response[@"isSucceed"] boolValue]) {
        [[NSUserDefaults standardUserDefaults] setObject:response[@"loginToken"] forKey:@"loginToken"];
        return true;
    }else{
        return false;
    }
}

@end
